class Solution:
    def canConvertString(self, s: str, t: str, k: int) -> bool:
        if len(s) != len(t):
            return False
        diff = {}
        for i in range(len(s)):
            d = ord(t[i]) - ord(s[i])
            if d < 0:
                d += 26
            if d == 0:
                continue
            if d > k:
                return False
            if d not in diff:
                diff[d] = 0
            diff[d] += 1
            cost = d + (diff[d] - 1) * 26
            if cost > k:
                return False
        return True
